package com.binyouwei.designpatterns.creation_type.singleton;

/**
 * @author 宾有为
 * @date 2024/6/20 20:16
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：单例模式 —— 静态内部类
 * 优点：延迟加载、线程安全。
 * 缺点：无法用于非静态内部类。
 **/
public class StaticInnerClass {
    private StaticInnerClass() {
    }

    private static class StaticInnerClassHolder {
        private static final StaticInnerClass INSTANCE = new StaticInnerClass();
    }

    public static StaticInnerClass getInstance() {
        return StaticInnerClassHolder.INSTANCE;
    }

    public void print() {
        System.out.println("Static Inner Class");
    }
}
